package ling.learn.syntax;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.FileUtils;

public class SyntaxReader {

  public static List<SyntaxRecord> read(File file) throws IOException {

    List<SyntaxRecord> records = new ArrayList<>();
    List<String> lines = FileUtils.readLines(file, Charset.forName("UTF-8"));
    for (String line : lines) {
      if (line.startsWith("ID")) {
        continue;
      }
      String[] words = line.split("\t");
      int i = 0;
      if (words.length >= 11) {
        SyntaxRecord record = new SyntaxRecord();
        record.statusNo = words[++i] + words[++i];
        record.keyWordParm = words[++i];
        record.nextNo = words[++i] + words[++i];
        record.language = words[++i];
        record.version = words[++i];
        record.keyKBN = words[++i];
        records.add(record);
      }
    }
    return records;
  }
}
